import { CrateTable } from "@/uni_modules/stars-UniTS-SQLite-ORM/components/stars-UniTS-SQLite-ORM/dbOrm/db/DBCrateTable";
import { executeSql } from "@/uni_modules/stars-UniTS-SQLite-ORM/components/stars-UniTS-SQLite-ORM/dbOrm/db/SqliteHelper";
import { User } from '@/pages/example/model/User';
import { DB_NAME } from '@/uni_modules/stars-UniTS-SQLite-ORM/components/stars-UniTS-SQLite-ORM/dbOrm/config/dbconfig';

export class TableInit {

	/**
	 * 初始化表
	 */
	public static tableInit() : void {
		const createProductTableSQL = CrateTable.generateCreateTableSQL(User);
		console.log(createProductTableSQL);
		executeSql(DB_NAME, createProductTableSQL);
		console.log("创建表成功：", User.name.toLowerCase());
		// TableInit.removeTable(User)
	}

	/**
	 * 需要删除的表
	 * 使用：TableInit.removeTable(User)
	 */
	public static removeTable(entityClass : Function) : void {
		executeSql(DB_NAME, `DROP TABLE IF EXISTS ${entityClass.name.toLowerCase()}`);
		console.log("删除表成功：", User.name);
	}

}